//============================================================================================
/**
 * @file	intro_obj.c
 * @brief	イントロ画面用OBJ制御
 * @author	Akito Mori
 * @date	2007.01.22
 */
//============================================================================================
#include "common.h"
#include "system/procsys.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/buflen.h"
#include "battle/battle_common.h"
#include "poketool/monsno.h"
#include "poketool/pokeparty.h"
#include "poketool/waza_tool.h"
#include "application/app_tool.h"
#include "system/arc_util.h"

#include "intro_sys.h"
#include "data/clact_util/clact_header.naix"

//============================================================================================
//	定数定義
//============================================================================================
// セルアクターのリソースID
enum {
	PST_CHR_ID_DOCTOR=0,	// 博士
	PST_CHR_ID_HERO_S,		// 下画面・男主人公
	PST_CHR_ID_HEROINE_S,	// 下画面・女主人公
	PST_CHR_ID_BTN_TOUCH_S,
	PST_CHR_ID_YESNO_CUR_S,
	PST_CHR_ID_MARIRU,

//	PST_CHR_ID_POKEMON,		// ポケモン
//	PST_CHR_ID_BALL,		// モンスターボール
//	PST_CHR_ID_HERO_M,		// 上画面主人公
//	PST_CHR_ID_CURSOR,		// カーソル
	PST_OBJ_MAX
};

#define CATS_DISTANCE	( 192 * FX32_ONE )

#define INTRO_DOCTOR_X	( 128 )
#define INTRO_DOCTOR_Y	( 50 )

#define INTRO_BALL_X	( 128 )
#define INTRO_BALL_Y	( 50 )

#define INTRO_POKEMON_X	( 128 )
#define INTRO_POKEMON_Y	( 50 )

#define INTRO_HERO_M_X	( 128 )
#define INTRO_HERO_M_Y	( 50 )


#define INTRO_HERO_S_X		( 64 )
#define INTRO_HERO_S_Y		( 104 )

#define INTRO_HEROINE_S_X	( 192 )
#define INTRO_HEROINE_S_Y	( 104 )

#define INTRO_BTN_TOUCH_S_X	( GX_LCD_SIZE_X )
#define INTRO_BTN_TOUCH_S_Y	( GX_LCD_SIZE_Y )

#define INTRO_MARIRU_X	( 20*8 )
#define INTRO_MARIRU_Y	( 10*8 )

#define INTRO_CURSOR_X	( 128 )
#define INTRO_CURSOR_Y	( 50 )


//============================================================================================
//============================================================================================


//============================================================================================
//============================================================================================
static const TCATS_OBJECT_ADD_PARAM	ActAddParam[] =
{

//	int no;				///< リソース内データの登録番号
//
//	s16 x;				///< [ X ] 座標
//	s16 y;				///< [ Y ] 座標
//	s16 z;				///< [ Z ] 座標
//
//	u16	anm;			///< アニメ番号
//	int pri;			///< 優先順位
//	int	pal;			///< パレット番号
//	int d_area;			///< 描画エリア
//

	{	// 博士
		PST_CHR_ID_DOCTOR, INTRO_DOCTOR_X, INTRO_DOCTOR_Y, 0,
		0, 2, 1, NNS_G2D_VRAM_TYPE_2DMAIN, 0, 0, 0, 0
	},
	{	// 下画面・男主人公
		PST_CHR_ID_HERO_S, INTRO_HERO_S_X, INTRO_HERO_S_Y, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DSUB, 0, 0, 0, 0
	},
	{	// 下画面・女主人公
		PST_CHR_ID_HEROINE_S, INTRO_HEROINE_S_X, INTRO_HEROINE_S_Y, 0,
		0, 1, 1, NNS_G2D_VRAM_TYPE_2DSUB, 0, 0, 0, 0
	},
	{	// 下画面・タッチボタン
		PST_CHR_ID_BTN_TOUCH_S, INTRO_BTN_TOUCH_S_X, INTRO_BTN_TOUCH_S_Y, 0,
		0, 0, 3, NNS_G2D_VRAM_TYPE_2DSUB, 0, 0, 0, 0
	},
	{	// 下画面・はい／いいえカーソル
		PST_CHR_ID_YESNO_CUR_S, 0, 0, 0,
		1, 0, 4, NNS_G2D_VRAM_TYPE_2DSUB, 0, 0, 0, 0
	},
	{	// マリル
		PST_CHR_ID_MARIRU, INTRO_MARIRU_X, INTRO_MARIRU_Y, 0,
		0, 0, 4, NNS_G2D_VRAM_TYPE_2DMAIN, 0, 0, 0, 0
	},
#if 0
	{	// モンスターボール
		PST_CHR_ID_BALL, INTRO_BALL_X, INTRO_BALL_Y, 0,
		0, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, 0, 0, 0, 0
	},
	{	// ポケモン
		PST_CHR_ID_POKEMON, INTRO_POKEMON_X, INTRO_POKEMON_X, 0,
		0, 1, 1, NNS_G2D_VRAM_TYPE_2DMAIN, 0, 0, 0, 0
	},
	{	// 上画面主人公
		PST_CHR_ID_HERO_M, INTRO_HERO_M_X, INTRO_HERO_M_Y, 0,
		0, 3, 2, NNS_G2D_VRAM_TYPE_2DMAIN, 0, 0, 0, 0
	},
	{	// カーソル
		PST_CHR_ID_CURSOR, INTRO_CURSOR_X, INTRO_CURSOR_X, 0,
		0, 2, 2, NNS_G2D_VRAM_TYPE_2DSUB, 0, 0, 0, 0
	},
#endif
};



//---------------------------------------------------------------------------------------------
/**
 * セルアクターシステム初期化
 *
 * @param	wk		ワーク
 *
 * @return	none
 */
//---------------------------------------------------------------------------------------------
void Intro_CellActInit( INTRO_DEMO_WORK * wk )
{
	GF_Disp_GX_VisibleControl(  GX_PLANEMASK_OBJ, VISIBLE_ON );		// MAIN DISP OBJ ON
	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );		// SUB DISP OBJ ON

	initVramTransferManagerHeap( 32, HEAPID_INTRO );

	wk->csp = CATS_AllocMemory( HEAPID_INTRO );
	wk->crp = CATS_ResourceCreate( wk->csp );

	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};
		TCATS_CHAR_MANAGER_MAKE ccmm = {
			INTRO_OBJ_MAX,
			1024,
			1024,
			GX_OBJVRAMMODE_CHAR_1D_32K,
			GX_OBJVRAMMODE_CHAR_1D_32K
		};
		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
		CATS_ClactSetInit( wk->csp, wk->crp, INTRO_OBJ_MAX );

		CLACT_U_SetSubSurfaceMatrix( CATS_EasyRenderGet( wk->csp ), 0, CATS_DISTANCE );
	}

	{
		//TCATS_RES_ARC
		TCATS_RESOURCE_FILE_LIST list = {
			NARC_clact_header_intro_chr_resdat,		// キャラクタ
			NARC_clact_header_intro_pal_resdat,		// パレット
			NARC_clact_header_intro_cell_resdat,	// セル
			NARC_clact_header_intro_canm_resdat,	// セルアニメ
			TCATS_RESID_NULL,						// マルチセル
			TCATS_RESID_NULL,						// マルチセルアニメ
			NARC_clact_header_intro_h_cldat			// ヘッダー
		};
		CATS_ResourceLoadBinary( wk->csp, wk->crp, &list );
	}
}

//---------------------------------------------------------------------------------------------
/**
 * セルアクターシステム削除
 *
 * @param	wk		ワーク
 *
 * @return	none
 */
//---------------------------------------------------------------------------------------------
void Intro_CellActRerease( INTRO_DEMO_WORK * wk )
{
	CATS_ResourceDestructor( wk->csp, wk->crp );
	CATS_FreeMemory( wk->csp );
	DellVramTransferManager();
	wk->crp=NULL;
}

//---------------------------------------------------------------------------------------------
/**
 * セルアクター追加
 *
 * @param	wk		ワーク
 *
 */
//---------------------------------------------------------------------------------------------
void Intro_CellActSet( INTRO_DEMO_WORK * wk )
{
	u16	i;

	for( i=0; i<6; i++ ){
		wk->awp[i] = CATS_ObjectAdd( wk->csp, wk->crp, &ActAddParam[i] );
	}

	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_DOCTOR], 0 );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HERO_S], 0 );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HEROINE_S], 0 );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 0 );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_YESNO_CUR_S], 0 );
	CLACT_BGPriorityChg( wk->awp[INTRO_OBJ_BTN_TOUCH_S], 1 );

	CLACT_SetAnmFlag( wk->awp[INTRO_OBJ_MARIRU], 1 );
	CLACT_SetAffineParam( wk->awp[INTRO_OBJ_MARIRU], CLACT_AFFINE_NORMAL );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_MARIRU], 0 );

#if 0
	{
		VecFx32 mat = {0};
		mat.x = INTRO_MARIRU_X
		CLACT_SetMatrix();
	}
#endif

//	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HERO_M], 1 );
//	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HERO_S], 1 );
//	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HEROINE_S], 1 );
//	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_CURSOR], 1 );

}

//==============================================================================
/**
 * @brief   下画面主人公を表示ON/OFFする
 *
 * @param   wk
 * @param   on_off	PM_MALE/PM_FEMALE/BOTH_ON/BOTH_OFF
 *
 * @retval  none
 */
//==============================================================================
void Intro_HeroHeroineVisible( INTRO_DEMO_WORK *wk, int on_off )
{
	int hero=0, heroine=0;
	if(on_off==PM_MALE){
		hero=1;
	}else if(on_off==PM_FEMALE){
		heroine=1;
	}else if(on_off==BOTH_ON){
		hero=1;
		heroine=1;
	}else if(on_off==BOTH_OFF){
		hero=0;
		heroine=0;
	}

	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HERO_S],    hero );
	CLACT_SetDrawFlag( wk->awp[INTRO_OBJ_HEROINE_S], heroine );

}

#if 0
static int debugobj=0;
//==============================================================================
/**
 * @brief   OBJの座標確認をするルーチン
 *
 * @param   wk
 *
 * @retval  none
 */
//==============================================================================
void intro_obj_test( INTRO_DEMO_WORK *wk )
{
	s16 wx,wy;
	if(sys.cont & PAD_KEY_UP){

		CATS_ObjectPosGet(wk->awp[debugobj], &wx, &wy);
		wy--;
		CATS_ObjectPosSet(wk->awp[debugobj], wx,  wy);
		OS_Printf("obj x=%d, y=%d\n", wx,wy);

	}else if(sys.cont & PAD_KEY_DOWN){
		CATS_ObjectPosGet(wk->awp[debugobj], &wx, &wy);
		wy++;
		CATS_ObjectPosSet(wk->awp[debugobj], wx,  wy);
		OS_Printf("obj x=%d, y=%d\n", wx,wy);
	}else if(sys.cont & PAD_KEY_LEFT){
		CATS_ObjectPosGet(wk->awp[debugobj], &wx, &wy);
		wx--;
		CATS_ObjectPosSet(wk->awp[debugobj], wx,  wy);
		OS_Printf("obj x=%d, y=%d\n", wx,wy);
	}else if(sys.cont & PAD_KEY_RIGHT){
		CATS_ObjectPosGet(wk->awp[debugobj], &wx, &wy);
		wx++;
		CATS_ObjectPosSet(wk->awp[debugobj], wx,  wy);
		OS_Printf("obj x=%d, y=%d\n", wx,wy);
	}else if(sys.trg & PAD_BUTTON_Y){
		if(++debugobj>2){
			debugobj=0;
		}
	}
}

#endif